package Sort.sort2018;

/**
 * Created by 雷文康 on 2018/2/26.
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] array = {3,8,4,6,7,2,5,9,1};
        bubbleSort(array);
        for (int i = 0; i < array.length; i++){
            System.out.print(array[i]);
        }
    }
    public static void bubbleSort(int[] array) {
        if (array == null || array.length == 0) {
            return;
        }
        boolean flag = true;
        for (int i = 0; i < array.length - 1 && flag; i++) {
            flag = false;
            for (int j = array.length - 1; j > i; j--) {
                if (array[j] < array[j - 1]) {
                    int temp = array[j];
                    array[j] = array[j - 1];
                    array[j - 1] = temp;
                    flag = true;
                }
            }
        }
    }
}
